<?php

namespace IDock\Insurance\YAIC\Response;

use IDock\Http\Response;
use IDock\Printer\PremiumUnderwritingPrinter;
use IDock\Visitor\Premium\PremiumInquiryVisitor;

class UnderwritingResponse extends AllYAICResponse
{

    /*** @var PremiumUnderwritingPrinter $printer */
    public $printer = PremiumUnderwritingPrinter::class;

    /*** @var PremiumInquiryVisitor $visitor */
    public $visitor;

    public function printerInit(): Response
    {
        $ciFlag = $ciFlag = false;
        $data = $this->getBody()['responseBody'] ?? [];
        $info = $data['proposalInfo']['ProposalDTO'] ?? [];
//        $error = '';
//        foreach ($info as $value ){
//            $code = $value['underwriteStatus'] ?? '';
//            if(in_array($value['underwriteStatus'],['B','0'])){
//                $code = $value['underwriteStatus'] ?? '';
//                $error = $value['errorMsg'] ?? '';
//                break;
//            }
//        }
        $payApp = '';
        $extInfo = $data['extendInfo']['ExtendInfoDTO'] ?? [];
        foreach ($extInfo as  $value){
            if(($value['key'] ?? '') == 'payAppNo'){
                $payApp = $value['value'] ?? '';
                break;
            }
        }
        $this->printer->ciInquiryNo = $data['proposalBZNo'] ?? '';
        $this->printer->biInquiryNo = $data['proposalNo'] ?? '';
//        $this->printer->messageTip = $error;
        if(!empty($payApp)){
            $this->printer->statusCode = 'U1';
            $this->printer->argc['payApp'] = $payApp;
            return $this;
        }
        //下发
//        if ($code == '0') {
//            $this->printer->statusCode = 'U4';
//        }
        //成功
//        if (in_array($code,['A','2']))  {
//            $this->printer->statusCode = 'U1';
//            $this->printer->argc['payApp'] = $data['payApp'] ?? '';
//        }
        //人工
//        if ($code == '1') {
//            $this->printer->statusCode = 'U3';
//        }
        $this->printer->statusCode = 'U4';
        return $this;
    }
}
